#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include <malloc.h>
#define MaxSize 100 
struct sq
{
    char name[MaxSize];
    double price;
};
int main() {
    struct sq people[20];
    int n;
    scanf("%d", &n);
    int maxp = 0;
    double max = 0;
    double min = 0;
    int minp = 0;
    for (int i = 0; i < n; i++) {
        getchar();
        gets_s(people[i].name);
            scanf("%lf", &people[i].price);
        if (i == 0) {
            max = people[0].price;
            min = people[0].price;
        }
        else {
            if (people[i].price > max) {
                max = people[i].price;
                maxp = i;
            }
            if (people[i].price < min) {
                min = people[i].price;
                minp = i;
            }
        }
    }
    printf("%0.2lf, %s\n", max, people[maxp].name);
    printf("%0.2lf, %s", min, people[minp].name);
    return 0;
}
